<template>
	<view class="home">

		<view class="popup">

			<view class="tits">
				修改密码
			</view>
			<view class="label">
				<view class="tit">
					原密码
				</view>
				<view class="input">
					<input v-model="oldpassword" password="true" placeholder="请输入原密码">
				</view>
			</view>
			<view class="label">
				<view class="tit">
					新密码
				</view>
				<view class="input">
					<input v-model="newpassword" password="true" placeholder="请输入新密码">
				</view>
			</view>

			<view class="label">
				<view class="tit">
					确认密码
				</view>
				<view class="input">
					<input v-model="renewpassword" password="true" placeholder="请输入确认密码">
				</view>
			</view>

			<view class="button" @click="changepwd();">
				确定修改
			</view>
			<view class="h">

			</view>
		</view>

	</view>
</template>

<script>
	import {
		request
	} from "@/request/index.js"
	import regeneratorRuntime from '@/lib/runtime/runtime'
	import {
		login
	} from "@/utils/asyncWx.js"
	export default {
		data() {
			return {
				oldpassword: "",
				newpassword: "",
				renewpassword: "",
				username: ""

			}
		},
		onLoad() {
			this.initUserInfo()
		},

		methods: {
			// 获取用户信息
			async initUserInfo() {

				var res = await request({
					url: "GetUserInfo"
				})
				console.log(res);
				if (res.code == 0) {

					this.username = res.data.username

				}

			},
			// 修改密码
			async changepwd() {
				if (this.oldpassword == "") {
					uni.showToast({
						title: "原密码不能为空",
						icon: "none"
					})

					return
				}
				if (this.newpassword == "") {
					uni.showToast({
						title: "新密码不能为空",
						icon: "none"
					})

					return
				}
				if (this.renewpassword == "") {
					uni.showToast({
						title: "确认密码不能为空",
						icon: "none"
					})

					return
				}

				if (this.renewpassword != this.newpassword) {
					uni.showToast({
						title: "新密码与确认密码不一致",
						icon: "none"
					})
					return
				}

				let data = {
					oldpassword: this.oldpassword,
					newpassword: this.newpassword,
					renewpassword: this.renewpassword,
					username: this.username
				}

				var res = await request({
					url: "changepwds",
					method: "post",
					data
				})
				if (res.code == 0) {
					uni.showToast({
						title: "修改成功请从新登录",
						icon: "none"
					})
					uni.removeStorageSync('token');
					uni.navigateTo({
						url: "/pages/login/login"
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				}
			},

		}
	}
</script>

<style>
	.init {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding-top: 60rpx;
	}

	.init image {
		width: 300rpx;
		height: 300rpx;
		margin: 0 auto;
	}

	.init .bb {
		margin: 60rpx auto;
		padding: 0 30rpx;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 15rpx;
		text-align: center;
		background-color: #0DC06E;
		margin-bottom: 0;
		font-size: 28rpx;
		color: #ffffff;
	}

	button::after {
		border: none;
		background-color: none;
	}

	button {

		margin-left: auto;
		margin-right: auto;
		padding-left: 0rpx;
		padding-right: 0rpx;
		box-sizing: border-box;

		text-align: left;
		text-decoration: none;
		font-size: 28rpx;
		line-height: 1.35;

		color: #000000;
		background-color: #fff;

	}

	.popup {
		width: 100%;
		height: 500rrpx;

		/* padding: 5%; */
		padding-top: 30rpx;
		background-color: #fff;


	}

	.h {
		width: 100%;
		height: 20rpx;
		margin-top: 35px;
		background-color: #F3F3F3;
	}

	.popup .tt {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 32rpx;
		font-weight: 700;
		margin-bottom: 20rpx;
	}

	.tits {
		margin-top: 20rpx;
		margin-left: 20rpx;
		font-weight: 700;
		font-size: 32rpx;
	}

	.popup .label {
		width: 100%;
		display: flex;
		height: 100rpx;
		align-items: center;
		position: relative;
		border-bottom: 2rpx solid #eee;
	}

	.popup .label .code {
		position: absolute;
		right: 20rpx;
		z-index: 4;
	}

	.popup .label button {
		width: 100% !important;
		height: 80rpx !important;

	}

	.popup .label button .css {

		display: flex !important;
		align-items: center !important;
		position: relative;
	}

	.popup .label .tit {
		width: 20% !important;
		font-size: 28rpx;
		margin-right: 10rpx;
		text-align: center;
	}

	.popup .label .img {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		overflow: hidden;
	}

	.input {
		width: 100%;
		height: 80rpx;
	}

	.popup .label .img image {
		width: 80rpx;
		height: 80rpx;
	}

	.popup .label input {
		width: 100%;
		height: 100%;
		background-color: #fff;

	}

	.popup .zuo {
		width: 14rpx;
		height: 25rpx;
		position: absolute;
		right: 0;
	}

	.popup .button {
		margin: 60rpx auto;
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 15rpx;
		text-align: center;
		background-color: #0DC06E;
		margin-bottom: 0;
		color: #ffffff;
	}
</style>